package org.zjt.spiextensiondemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.PayloadApplicationEvent;

import static java.lang.System.err;

@SpringBootApplication
public class SpiExtensionDemoApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(SpiExtensionDemoApplication.class, args);
		configurableApplicationContext.addApplicationListener( event -> {
			if (event instanceof PayloadApplicationEvent){
				Object payload = PayloadApplicationEvent.class.cast(event).getPayload();
				err.println("spring payload 事件: "+payload);
			}else
			err.println("spring event 事件: "+event);
		});

		// 发送payload 事件
		configurableApplicationContext.publishEvent(111111111111L);
	}
}
